import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getUserInfo } from '@/api/user'

export const useLoginUserStore = defineStore('loginUser', () => {
  const loginUser = ref<any>({
    username: '未登录'
  })
  // 远程获取登录用户信息
  async function fetchLoginUser() {
    const res = await getUserInfo()
    if (res.data.data === 0 && res.data.data) {
      loginUser.value = res.data.data
    }
  }
  // 单独设置信息
  function setLoginUser(newLoginUser: any) {
    loginUser.value = newLoginUser
  }
  return { loginUser, fetchLoginUser, setLoginUser }
})
